//
//  XMLhelpers.h
//  tjp_helper
//
//  Created by Daniel Braun on 28/01/07.
//  Copyright 2007 Daniel Braun http://braun.daniel.free.fr. All rights reserved.
//

#import <Cocoa/Cocoa.h>



static inline NSXMLElement *firstValueForXML(NSXMLElement *el, NSString *name)
{
	NSArray *a=[el elementsForName:name];
	if (!a) return nil;
	if (![a count]) return nil;
	return [a objectAtIndex:0];
}
static inline NSString *firstStringValueForXML(NSXMLElement *el, NSString *name)
{
	return [firstValueForXML(el, name) stringValue];
}

@interface XmlAccessor : NSObject {
	NSString *target_field;
	NSString *target_attrib;
	SEL xmlConverter;
	SEL stringConverter;
}

+ (id) xmlAccessorWith:(NSString *)s attrib:(NSString *)a 
     xmlConverter:(SEL) c1 stringConverter:(SEL)c2;
- (id) applyWith:(NSXMLElement*)s;

@end

@interface NSXMLElement (XMLvalueConversion)
- (NSNumber *) convertToNumber;
- (NSNumber *) convertToDate;
- (NSNumber *) convertToBool;

@end
